package com.bizmerce.rnd.oms.reporting.web;

import java.awt.Color;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.view.document.AbstractPdfView;

import com.lowagie.text.Cell;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfWriter;

/**
 * TODO  
 * 
 * @author Gyeseon
 *
 */
public class PdfView extends AbstractPdfView {

	protected void buildPdfDocument(Map model, Document document,
			PdfWriter writer, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		
//		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Korea_Chile.pdf"));
//		document.open();
		BaseFont baseFont = BaseFont.createFont("HYGoThic-Medium", "UniKS-UCS2-H", BaseFont.NOT_EMBEDDED);
		Font headerFont = new Font(baseFont, 16, Font.BOLD, Color.black);
		Font defaultFont = new Font(Font.HELVETICA, 11);
		Font boldFont = new Font(Font.HELVETICA, 14, Font.BOLD);
		Font issuingFont = new Font(Font.HELVETICA, 12, Font.NORMAL);
		
		//TITLE
		Paragraph paragraph;
		paragraph = new Paragraph("<양식 3>한-칠레 FTA 원산지증명서",headerFont);
		document.add(paragraph);
		
		paragraph = new Paragraph("KOREA-CHILE FREE TRADE AGREEMENT",boldFont);
		paragraph.setAlignment(Element.ALIGN_CENTER);
		document.add(paragraph);
		
		paragraph = new Paragraph("CERTIFICATE OF ORIGIN",boldFont);
		paragraph.setAlignment(Element.ALIGN_CENTER);
		document.add(paragraph);
		
		paragraph = new Paragraph("Issuing Number :                                    ",issuingFont);
		paragraph.setAlignment(Element.ALIGN_RIGHT);
		document.add(paragraph);
		
		//TABEL WITH INFORMATION
		Table table;
		Cell cell;
		table = new Table(6);
		table.setWidth(100);
		cell = new Cell(new Paragraph("1 : Exporter(Name and Address)",defaultFont));
		Chunk chunk2 = new Chunk("\n"+"                                                                       ");
		cell.add(chunk2);
		chunk2 = new Chunk("Tax ID No : ",defaultFont);
		
		cell.add(chunk2);
		table.setPadding(5);
		cell.setColspan(6);
		table.addCell(cell);
		
		cell = new Cell(new Paragraph("2 : Producer(Name and Address)",defaultFont));
		Chunk chunk = new Chunk("                                    Tax ID No : ",defaultFont);
		cell.add(chunk);
		cell.setColspan(3);
		table.addCell(cell);
		
		cell = new Cell(new Paragraph("3 : Importer(Name and Address)",defaultFont));
		cell.setColspan(3);
		table.addCell(cell);

		cell = new Cell(new Paragraph("4. Description of Good(s)",defaultFont));
		cell.setColspan(2);
		
		table.getDefaultCell().setHorizontalAlignment(
				Element.ALIGN_CENTER);
		table.addCell(cell);
		table.addCell(new Paragraph("5. HS No.",defaultFont));
		table.addCell(new Paragraph("6. Preference Criterion",defaultFont));
		table.addCell(new Paragraph("7. Regional Value Content",defaultFont));
		table.addCell(new Paragraph("8. Country of Origin",defaultFont));
		
		cell = new Cell(new Paragraph(""));
		cell.setColspan(2);
		table.addCell(cell);
		cell = new Cell(new Paragraph(""));
		table.addCell(cell);
		cell = new Cell(new Paragraph(""));
		table.addCell(cell);
		cell = new Cell(new Paragraph(""));
		table.addCell(cell);
		cell = new Cell(new Paragraph(""));
		table.addCell(cell);
		
		cell = new Cell(new Paragraph("9. Remarks : ",defaultFont));
		table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
		cell.setColspan(6);
		table.addCell(cell);
		
		cell = new Cell(new Paragraph("10 : Certification of Origin", defaultFont));
		cell.setColspan(6);
		Chunk chunk1 = new Chunk("I Certify that : ",defaultFont);
		cell.addElement(chunk1);
		chunk1 = new Chunk("\n"+"   |  The information on this document is true and accurate and I assume the responsibility for providing", defaultFont);
		cell.addElement(chunk1);
		chunk1 = new Chunk("\n"+"      such representations. I understand that I am liable for any false statements or material omissions", defaultFont);
		cell.addElement(chunk1);
		chunk1 = new Chunk("\n"+"      made on or in connection with this document", defaultFont);
		cell.addElement(chunk1);
		chunk1 = new Chunk("\n"+"   |  I agree to maintain and present upon request, documentation necessary to support this certificate,", defaultFont);
		cell.addElement(chunk1);
		chunk1 = new Chunk("\n"+"      and to inform, in writing, all persons to whom the certificate was given of any changes that could ", defaultFont);
		cell.addElement(chunk1);
		chunk1 = new Chunk("\n"+"      affect the accuracy or validity of this certificate.", defaultFont);
		cell.addElement(chunk1);
		
		chunk1 = new Chunk("\n"+"   |  The goods originated in the territory of the parties, and comply with the origin requirements specified", defaultFont);
		cell.addElement(chunk1);
		chunk1 = new Chunk("\n"+"      for those goods in KOREA-CHILE FREE TRADE AGREEMENT. and there has been no further", defaultFont);
		cell.addElement(chunk1);
		chunk1 = new Chunk("\n"+"      production or any other operation outside the territories of the Parties in accordance with Article", defaultFont);
		cell.addElement(chunk1);
		chunk1 = new Chunk("\n"+"      4.12 of the Agreement.", defaultFont);
		cell.addElement(chunk1);
		table.addCell(cell);
				
		cell = new Cell(new Paragraph("Authorized Signature",defaultFont));
		cell.setColspan(3);
		table.addCell(cell);
		
		cell = new Cell(new Paragraph("Company Name",defaultFont));
		cell.setColspan(3);
		table.addCell(cell);
		
		cell = new Cell(new Paragraph("Name(Print or Type)",defaultFont));
		cell.setColspan(3);
		table.addCell(cell);
		
		cell = new Cell(new Paragraph("Title",defaultFont));
		cell.setColspan(3);
		table.addCell(cell);
		
		cell = new Cell(new Paragraph("Date(MM/DD/YY)",defaultFont));
		cell.setColspan(3);
		table.addCell(cell);
		
		cell = new Cell(new Paragraph("Telephone/Fax/Email",defaultFont));
		cell.setColspan(3);
		table.addCell(cell);
		
		document.add(table);
//		document.close();
	}
}
